package redisDB

import (
	"reflect"

	"github.com/go-redis/redis"
)

//添加映射
// @client 连接对象
// @dataName 数据库名
func DataBaseMapping(client redis.Cmdable) *RedisContent {
	return &RedisContent{client: client}
}

//集合上下文
type RedisContent struct {
	client redis.Cmdable
}

//获取集合仓储
// entity 结构体
func (r *RedisContent) GetRedisRepository(entity interface{}) IRedisRepository {
	var entityName string
	typeOfCat := reflect.TypeOf(entity)
	if typeOfCat.Kind() == reflect.Ptr {
		entityName = typeOfCat.Elem().Name()
	}else {
		entityName = typeOfCat.Name()
	}
	return &ReidsRepository{
		client:     r.client,
		entityName: entityName,
	}
}
